Add `cargo check --all`
authorAlex Crichton <alex@alexcrichton.com>
Fri, 17 Feb 2017 17:09:23 +0000 (09:09 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 17 Feb 2017 18:53:56 +0000 (10:53 -0800)
This'll check all `build` targets for all packages in a workspace

src/bin/check.rs
tests/check.rs

index de8a9c6040cfe5b368b687811bea8a3158ed3e6d..e13c68b2556aca8f9b534ab222ee21bdda0209ae 100644 (file)
@@ -1,7 +1,7 @@
 use std::env;
 
 use cargo::core::Workspace;
-use cargo::ops::{self, CompileOptions, MessageFormat};
+use cargo::ops::{self, CompileOptions, MessageFormat, Packages};
 use cargo::util::{CliResult, Config};
 use cargo::util::important_paths::find_root_manifest_for_wd;
 
@@ -13,7 +13,8 @@ Usage:
 
 Options:
     -h, --help                   Print this message
-    -p SPEC, --package SPEC ...  Package to check
+    -p SPEC, --package SPEC ...  Package(s) to check
+    --all                        Check all packages in the workspace
     -j N, --jobs N               Number of parallel jobs, defaults to # of CPUs
     --lib                        Check only this package's library
     --bin NAME                   Check only the specified binary
@@ -64,6 +65,7 @@ pub struct Options {
     flag_bench: Vec<String>,
     flag_locked: bool,
     flag_frozen: bool,
+    flag_all: bool,
 }
 
 pub fn execute(options: Options, config: &Config) -> CliResult {
@@ -79,6 +81,12 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
     let ws = Workspace::new(&root, config)?;
 
+    let spec = if options.flag_all {
+        Packages::All
+    } else {
+        Packages::Packages(&options.flag_package)
+    };
+
     let opts = CompileOptions {
         config: config,
         jobs: options.flag_jobs,
@@ -86,7 +94,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
         features: &options.flag_features,
         all_features: options.flag_all_features,
         no_default_features: options.flag_no_default_features,
-        spec: ops::Packages::Packages(&options.flag_package),
+        spec: spec,
         mode: ops::CompileMode::Check,
         release: options.flag_release,
         filter: ops::CompileFilter::new(options.flag_lib,
index b01d88e952d95daa848e7577b56caedfff635c81..a47242ce8b5945ddb50999ed1a508e89b2858dcd 100644 (file)
@@ -383,3 +383,41 @@ fn rustc_check_err() {
                    .arg("--emit=metadata"),
                 execs().with_status(101));
 }
+
+#[test]
+fn check_all() {
+    if !is_nightly() {
+        return
+    }
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [workspace]
+            [dependencies]
+            b = { path = "b" }
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .file("examples/a.rs", "fn main() {}")
+        .file("tests/a.rs", "")
+        .file("src/lib.rs", "")
+        .file("b/Cargo.toml", r#"
+            [package]
+            name = "b"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("b/src/main.rs", "fn main() {}")
+        .file("b/src/lib.rs", "");
+
+    assert_that(foo.cargo_process("check").arg("--all").arg("-v"),
+                execs().with_status(0)
+        .with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]")
+        .with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]")
+        .with_stderr_contains("[..] --crate-name b b[/]src[/]lib.rs [..]")
+        .with_stderr_contains("[..] --crate-name b b[/]src[/]main.rs [..]")
+        );
+}